package com.fuyao.cloud.admin.flow.actor;

import com.fuyao.cloud.flowable.entity.ActorUser;
import com.fuyao.cloud.admin.api.entity.SysUser;
import com.fuyao.cloud.flowable.vo.ActorInstance;
import com.fuyao.cloud.admin.service.SysUserService;
import com.fuyao.cloud.common.security.service.CloudUser;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;


@Component("originLevelDeptUserRule")
public class OriginLevelDeptUserRule implements ActorRule {

    @Override
    public String getName() {
        return "当前用户所属部门用户";
    }

    @Override
    public String getCode() {
        return "ORIGIN_LEVEL_DEPT_USER_RULE";
    }

    @Override
    public int getArgNum() {
        return 0;
    }

    @Override
    public String[] getArgsDesc() {
        return new String[0];
    }

    @Autowired
    private SysUserService userService;

    @Override
    public List<ActorInstance> execute(CloudUser cloudUser, ActorUser actorUser, String businessKey) {
        List<ActorInstance> actorInstances = Lists.newArrayList();
        List<SysUser> userList = this.userService.listByDeptIds(Collections.singletonList(cloudUser.getDeptId()));
        userList.forEach(user -> {
            ActorInstance actorInstance = new ActorInstance(user);
            actorInstances.add(actorInstance);
        });
        return actorInstances;
    }
}
